#!/usr/bin/env python2.7
# coding=utf-8
# Created by han on 2016/5/13
#print("欢迎查看地铁首末班时刻表")
import  time
subway_dict = {
    "北京":{
        "五号线":{
            "天通苑北站":["4:50","23:59"],
            "宋家庄站":["5:00","24:00"]},
        "一号线":{
            "苹果园站":["4:44","23:30"],
            "四惠东站":["4:20","23:11"]},
        "昌平线":{
            "昌平西山口站":["4:10","22:59"],
            "西二旗站":["5:20","23:10"]}},
    "天津": {
        "一号线":{
            "刘园站":["5:44","22:30"],
            "双林站":["6:10","22:10"]},
        "二号线": {
            "滨海国际机场站":["5:24","22:10"],
            "曹庄站":["5:44","22:05"]},
        "三号线": {
            "小淀站":["6:05","22:13"],
            "南站站":["6:00","22:29"]},
        }
    }
while True:
    list1=[]
    print('''欢迎使用中国地铁
------''')
    for i in range(len(subway_dict.keys())):     #把第一层的key的数量赋值给i 天津，北京 2赋值给i
        a2="%s" % (subway_dict.keys()[i])        #打印每次循环打印对应的key
        print(a2)
        list1.append(a2)
    print("------\n")
    user_input1 = raw_input("输入您的查询的城市【1】or【2】:")
    if user_input1=="1":                                #天津
        while True:
            list2 = []
            print("========")
            for j in subway_dict[list1[0]]:
                print(j)
                list2.append(j)
            print("========")
            print("b返回上一级")
            print("q 退出\n")
            user_input2=raw_input("输入您查询的线路【1】【2】【3】： ")
            if user_input2=='1':                                    #天津二号线
                while True:
                    list3=[]
                    print("----------")
                    for n in subway_dict[list1[0]][list2[0]]:
                        print(n)
                        list3.append(n)
                    print("----------")
                    print("b 返回上一级")
                    print("q 退出程序\n")
                    user_input3=raw_input("输入您查询的始发站发车时间【1】or【2】： ")
                    if user_input3=='1':
                        print("================")
                        print(subway_dict[list1[0]][list2[0]][list3[0]])
                        print("================\n")
                    elif user_input3=='2':
                        print("================")
                        print(subway_dict[list1[0]][list2[0]][list3[1]])
                        print("================\n")
                    elif user_input3=='q':
                        exit()
                    elif user_input3=='b':
                        break
                    else:
                        continue
            elif user_input2 == '2':                              # 天津1号线
                while True:
                    list5 = []
                    print("----------")
                    for n in subway_dict[list1[0]][list2[1]]:
                        print(n)
                        list5.append(n)
                    print("----------")
                    print("b 返回上一级")
                    print("q 退出程序\n")
                    user_input3 = raw_input("输入您查询的始发站发车时间【1】or【2】： ")
                    if user_input3 == '1':
                        print("================")
                        print(subway_dict[list1[0]][list2[1]][list5[0]])
                        print("================\n")
                    elif user_input3 == '2':
                        print("================")
                        print(subway_dict[list1[0]][list2[1]][list5[1]])
                        print("================\n")
                    elif user_input3 == 'q':
                        exit()
                    elif user_input3 == 'b':
                        break
                    else:
                        continue
            elif user_input2=='3':                           #天津3号线
                while True:
                    list6 = []
                    print("----------")
                    for n in subway_dict[list1[0]][list2[2]]:
                        print(n)
                        list6.append(n)
                    print("----------")
                    print("b 返回上一级")
                    print("q 退出程序\n")
                    user_input3 = raw_input("输入您查询的始发站发车时间【1】or【2】：")
                    if user_input3 == '1':
                        print("================")
                        print(subway_dict[list1[0]][list2[2]][list6[0]])
                        print("================\n")
                    elif user_input3 == '2':
                        print("================")
                        print(subway_dict[list1[0]][list2[2]][list6[1]])
                        print("================\n")
                    elif user_input3 == 'q':
                        exit()
                    elif user_input3 == 'b':
                        break
                    else:
                        continue
            elif user_input2=="b":
                break
            elif user_input2=="q":
                exit()


    elif user_input1=="2":                      #北京
        while True:
            list3=[]
            print("========")
            for n in subway_dict[list1[1]]:
                print(n)
                list3.append(n)
            print("========")
            print("b返回上一级")
            print("q退出\n")
            user_input2=raw_input('输入您查询的线路【1】【2】【3】： ')
            if user_input2=="1":                                         #五号线
                while True:
                    list4=[]
                    print("----------")
                    for o in subway_dict[list1[1]][list3[0]]:
                        print(o)
                        list4.append(o)
                    print("----------")
                    print("b 返回上一级")
                    print("q 退出程序\n")
                    user_input4=raw_input('输入:')
                    if user_input4=="1":
                        print("================")
                        print(subway_dict[list1[1]][list3[0]][list4[0]])
                        print("================\n")
                    elif user_input4=='2':
                        print("================")
                        print(subway_dict[list1[1]][list3[0]][list4[1]])
                        print("================\n")
                    elif user_input4=='q':
                        exit()
                    elif user_input4=='b':
                        break
                    else:
                        continue
            elif user_input2=="2":                                       #昌平线
                while True:
                    list7 = []
                    print("----------")
                    for n in subway_dict[list1[1]][list3[1]]:
                        print(n)
                        list7.append(n)
                    print("----------")
                    print("b 返回上一级")
                    print("q 退出程序\n")
                    user_input2 = raw_input('输入：')
                    if user_input2 == "1":
                        print("================")
                        print(subway_dict[list1[1]][list3[1]][list7[0]])
                        print("================\n")
                    elif user_input2 == '2':
                        print("================")
                        print(subway_dict[list1[1]][list3[1]][list7[1]])
                        print("================\n")
                    elif user_input2 == 'q':
                        exit()
                    elif user_input2 == 'b':
                        break
                    else:
                        continue
            elif user_input2 == "3":                                    # 一号线
                while True:
                    list8 = []
                    print("----------")
                    for n in subway_dict[list1[1]][list3[2]]:
                        print(n)
                        list8.append(n)
                    print("----------")
                    print("b 返回上一级")
                    print("q 退出程序\n")
                    user_input3 = raw_input('输入：')
                    if user_input3 == "1":
                        print("================")
                        print(subway_dict[list1[1]][list3[2]][list8[0]])
                        print("================\n")
                    elif user_input3 == '2':
                        print("==================")
                        print(subway_dict[list1[1]][list3[2]][list8[1]])
                        print("==================\n")
                    elif user_input3 == 'q':
                        exit()
                    elif user_input3 == 'b':
                        break
                    else:
                        continue
            elif user_input2=="b":
                break
            elif user_input2=="q":
                exit()
            else:
                continue